<template>
  <el-dialog
    v-model="show"
    :title="dailogTitle"
    width="480px"
    modal-class="docDetailDivideVotes-dailog"
  >
    <div style="height: 100%" class="divide-votes">
      <el-form
        ref="addFormRef"
        :model="addForm"
        label-suffix=":"
        label-width="90px"
        :rules="rules"
        :show-message="false"
      >
        <el-row>
          <el-col :span="24">
            <el-form-item label="主提单号">
              <!-- <el-select
                v-model="addForm.BillType"
                placeholder="请选择"
                style="width: 100%"
                clearable
                filterable
              >
                <el-option label="MBL" value="MBL"> </el-option>
                <el-option label="HBL" value="HBL"> </el-option>
              </el-select> -->
              <el-input
                v-model="BillType"
                placeholder="请输入"
                style="width: 100%"
                disabled
              ></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="24">
            <el-form-item label="分票数量" prop="Count">
              <el-input
                v-model="addForm.Count"
                placeholder="请输入"
                style="width: 100%"
                clearable
                @input="checkCount"
              ></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="24">
            <el-form-item label="编号规则" prop="Rule">
              <el-select
                v-model="addForm.Rule"
                placeholder="请选择"
                style="width: 100%"
                clearable
                filterable
              >
                <el-option label=".......1,2,3,4" :value="1"> </el-option>
                <el-option label=".......A,B,C,D" :value="0"> </el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
    </div>
    <template #footer>
      <div>
        <el-button type="default" @click="show = false">取消</el-button>
        <el-button type="primary" @click="modifySubmit">保存</el-button>
      </div>
    </template>
  </el-dialog>
</template>

<script>
import { defineComponent } from 'vue'
import AppSearchForm from '@/components/AppSearchForm.vue'
import AppPageTable, { useTableOption } from '@/components/AppPageTable2'
import { validateOnlyNumberTwo, validateNumber } from '@/utils/validate.js'
import dayjs from 'dayjs'
import { ElMessage } from 'element-plus'
export default defineComponent({
  components: {
    AppSearchForm,
    AppPageTable
  },
  computed: {},
  watch: {},
  props: {},
  data() {
    return {
      dailogTitle: '分票',
      show: false,
      BillType: '', ///提单类型
      addForm: {
        id: this.$route.query.id,

        Count: '', //分票数量
        Rule: '' //Rule
      },
      showCheck: false,
      rules: {
        // BillType: [
        //   {
        //     required: true,
        //     message: '请选择提单类型',
        //     trigger: 'change'
        //   }
        // ],
        Count: [
          {
            required: true,
            message: '请输入分票数量',
            trigger: 'blur'
          }
        ],
        Rule: [
          {
            required: true,
            message: '请选择编号规则',
            trigger: 'change'
          }
        ]
      }
    }
  },
  methods: {
    validateNumber,
    // row
    open(row) {
      this.show = true
      this.$nextTick(() => {
        this.$refs.addFormRef.resetFields()
        this.BillType = row
      })
    },

    checkCount(val) {
      let valFomat = validateNumber(val)
      if (parseInt(valFomat) <= 1) {
        this.addForm.Count = ''
      } else {
        this.addForm.Count = validateNumber(val)
      }
    },
    // 新增
    modifySubmit() {
      this.$confirm('分票后，集装箱装载明细内容是否需要进行平拆', '分票', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        this.$refs.addFormRef.validate(async (valid) => {
          if (valid) {
            let addForm = JSON.parse(JSON.stringify(this.addForm))
            // addForm.Count = parseInt(addForm.Count)
            let res = await this.$http.post(
              '/api/sebooking/splitbooking',
              addForm
            )
            if (res.status) {
              this.$emit('getTicket')
              this.show = false
            } else {
              this.$message.warning(res.message)
            }
          }
        })
      })
    }
  }
})
</script>

<style lang="scss">
.docDetailDivideVotes-dailog {
  .el-dialog__header {
    border-bottom: 1px solid #e8e8e8;
    padding: 7px 16px 7px 16px;
  }

  .el-dialog {
    padding: 0px;
  }

  .el-dialog__body {
    padding: 16px 24px 4px;
  }

  .el-dialog__footer {
    border-top: 1px solid #e8e8e8;
    padding: 8px;
    text-align: center;
  }
}
</style>
<style lang="scss" scoped>
.divide-votes {
  :deep(.el-form-item--small .el-form-item__label) {
    color: #000000d8;
    font-family: PingFang SC;
    font-weight: normal;
    font-size: 12px;
    line-height: 20px;
    letter-spacing: 0px;
  }

  :deep(.el-form--inline .el-form-item) {
    display: flex;
    margin-right: 0;
  }

  :deep(.el-form-item--small.el-form-item) {
    margin-bottom: 12px !important;
  }

  :deep(.el-row) {
    padding-right: 0px !important;
    margin-bottom: 0px !important;
  }
}
</style>
